package com.slt.android.remoteview;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    ImageView iv , iv2 , iv3;
    Button btn , btn2 , btn3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        initNotify();
        inintImage();
    }

    private void inintImage() {
        iv = (ImageView) findViewById(R.id.iv);
        iv2 = (ImageView) findViewById(R.id.iv2);
        iv3 = (ImageView) findViewById(R.id.iv3);

        btn = (Button) findViewById(R.id.btn);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);

        btn.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
    }

    private void initNotify() {

        Intent intent = new Intent(this , SecondActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this , 0 , intent , PendingIntent.FLAG_UPDATE_CURRENT);

        Notification notification = new Notification.Builder(this)
                .setAutoCancel(true)
                .setContentTitle("title")
                .setContentText("describe")
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setWhen(System.currentTimeMillis())
                .build();

        NotificationManager nfm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nfm.notify(1 , notification);


    }

    boolean b;
    @Override
    public void onClick(View v) {

        if(v == btn){
            b = !b;
            if(b){
                iv.setImageLevel(15);

            }else {
                iv.setImageLevel(5);
            }
        }else if(v == btn2) {
            TransitionDrawable td = (TransitionDrawable) iv2.getDrawable();
//            td.startTransition(1000);
            td.reverseTransition(1000);
        }else {
            /** 返回iv3内部图片的实际大小，与控件大小无关、单位为dp*/
            int w = iv3.getDrawable().getIntrinsicWidth();
            int h = iv3.getDrawable().getIntrinsicHeight();

            Toast.makeText(MainActivity.this , "width == " + w +  "height == " + h, Toast.LENGTH_SHORT).show();
        }


    }
}
